<?php namespace Home\Controller; 
use Hdphp\Controller\Controller;
/**
 *  评论控制器
 */
class CommentController extends Controller{
	public function comment(){
		if (IS_AJAX) {
			$nickname = Q('post.nickname');
			$content = Q('post.content');
			$aid = Q('post.aid',0,'intval');
			$str = '';
			if (empty($nickname) || empty($content)) {
				echo $str = 0;
			}
			//验证通过写入数据
			$data = array(
				'nickname' => $nickname,
				'content' => $content,
				'addtime' => time(),
				'article_aid' => $aid
				);
			if (Db::table('comment')->insertGetId($data)){
			      $time = date('Y-m-d H:i:s',$data['addtime']);
$str=<<<str
	<div class="author">
                <h3>{$data['nickname']}:</h3>
                <div class="alignleft"></div>
                <div class="author-desc">
                 <span class="tdate">{$time}</span>
                 <p>{$data['content']}</p>
                </div>
            </div>
            <div class="separator"></div>
str;
				echo $str;
			}
		}
	}

	//文章点赞
	public function praise(){
		if (IS_AJAX) {
			$aid = Q('post.aid',0,'intval');
			if (Db::table('article')->where(array('aid'=>$aid))->increment('praise')) {
				$aids = Db::table('article')->where(array('aid'=>$aid))->pluck('praise');
				echo json_encode(array('status'=>1,'msg'=>$aids));die;
			}
		}
	}

}